package org.lemon.db.tx;

import org.lemon.db.store.Page;

/**
 * @since 2024-12-13 17:30
 */
public class CheckPointRecord extends LogRecord{

    public CheckPointRecord() {
    }

    public CheckPointRecord(int txNum) {
        super(txNum);
    }

    @Override
    public RecordType op() {
        return RecordType.CHECKPOINT;
    }

    @Override
    public String toString() {
        return "<CHECKPOINT>";
    }

    @Override
    protected int decode(Page p) {
        int code = p.getInt(0);
        if(code != op().getCode()){
            throw new IllegalStateException("decode failure !");
        }
        return 4;
    }

    @Override
    protected byte[] encode() {
        byte[] result = new byte[4];
        Page p =  Page.create(result);
        p.setInt(0,op().getCode());
        return result;
    }
}
